/**
 * 
 */
package com.lion.jacoco.web.home.module.screen;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.lion.jacoco.biz.JsonUtil;
import com.lion.jacoco.biz.RequestResult;
import com.lion.jacoco.manager.AppManager;

/**
 * InitSystem.java. 2011-11-30下午6:47:58 @author LionBule.
 */
public class InitSystem {
    @Autowired
    private HttpServletResponse response;
    @Autowired
    private AppManager          appManager;

    public void execute(@Param("type") final int type, Context context) throws Exception {
        response.setContentType("text/plain; charset=UTF-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
            final AppManager tempAppManager = appManager;
            Thread task = new Thread(new Runnable() {

                @Override
                public void run() {
                    tempAppManager.InitSystem(type);
                }

            });
            task.setName("JacocoInitSystem");
            task.start();
            out.print(JsonUtil.getJsonStr(new RequestResult(true,
                    "Already in operation, please check the result later.", null)));
        } catch (Exception e) {
            out.print(JsonUtil.getJsonStr(new RequestResult(false, "System exception.", null)));
        } finally {
            out.flush();
        }
    }

}
